#include <stdio.h>
#include <stdbool.h>

struct date
{
  int year;
  int month;
  int day;
};

struct date getTomorrow(struct date today);
int dayOfMonth(int year, int month);
bool isLeapYear(int year);

int main(int argc, char const *argv[])
{
  struct date today, tomorrow;
  printf("Enter today's date (yyyy mm dd): ");
  scanf("%i%i%i", &today.year, &today.month, &today.day);
  tomorrow = getTomorrow(today);
  printf("Day of month in %i:", today.year);
  for (int i = 1; i <= 12; i++)
  {
    printf("%i - %i   ", i, dayOfMonth(today.year, i));
  }
  printf("Tomorrow's date is %i/%.2i/%.2i\n", tomorrow.year, tomorrow.month, tomorrow.day);
  return 0;
}

//获取指定日期后的一天
struct date getTomorrow(struct date today)
{
  struct date tomorrow;
  if (today.day < dayOfMonth(today.year, today.month))
  {
    tomorrow.year = today.year;
    tomorrow.month = today.month;
    tomorrow.day = today.day + 1;
  }
  else if (today.month == 12)
  {
    //年末
    tomorrow.year = today.year + 1;
    tomorrow.month = 1;
    tomorrow.day = 1;
  }
  else
  {
    //月末
    tomorrow.year = today.year;
    tomorrow.month = today.month + 1;
    tomorrow.day = 1;
  }
  return tomorrow;
}

//获取某年某月的总天数
int dayOfMonth(int year, int month)
{
  if (month == 2)
  {
    if (isLeapYear(year))
    {
      return 29;
    }
    return 28;
  }
  else if (month < 8)
  {
    if (month % 2 == 1)
    {
      return 31;
    }
    return 30;
  }
  else
  {
    if (month % 2 == 0)
    {
      return 31;
    }
    return 30;
  }
}

//判断year是否为闰年，4年一闰，100年不闰，400年再闰
bool isLeapYear(int year)
{
  return (year % 4 == 0 && year % 100 != 0) || year % 400 == 0;
}
